<?php


namespace LazadaApi\Services;


class LazadaGlobalProductService extends BaseLazadaService
{
    /**
     * 使用此API为多个Lazada站点创建单个新的全球产品 在每个站点上创建全局产品需要几分钟。
     *
     * @see     https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=18&path=/product/global/create
     *
     * @param array $productData
     *
     * @example $productData
     * {
     *    "Product": {
     *        "PrimaryCategory": "6576",
     *        "SPUId": "",
     *        "AssociatedSku": "",
     *        "Attributes": {
     *            "name": "Cheese forest Indian children's tent play house children's ",
     *            "brand": "No Brand",
     *            "short_description": "商品描述信息",
     *        },
     *        "Skus": [
     *            {
     *                "Sku": {
     *                    "color_family": "White_Not Specified",
     *                    "size": "Not Specified",
     *                    "SellerSku": "1051-12883-White-Not Specified",
     *                    "price": 0,
     *                    "package_weight": 4,
     *                    "package_length": 160,
     *                    "package_width": 12,
     *                    "package_height": 12,
     *                    "Status": "inactive",
     *                    "quantity": 1111,
     *                    "Images": [
     *                        {
     *                            "Image": "https://my-live-02.slatic.net/p/5554bc476b8167ed8aeeb9f09d4e1993.jpg"
     *                        },
     *                        {
     *                            "Image": "https://my-live-02.slatic.net/p/1172eaa46b28776f9ffe944e3c7d4cd8.jpg"
     *                        },
     *                        {
     *                            "Image": "https://my-live-02.slatic.net/p/73ff045b9c71873fc8078a14a1218e76.jpg"
     *                        }
     *                    ]
     *                }
     *            },
     *            {
     *                "Sku": {
     *                    "color_family": "Blue_Not Specified",
     *                    "size": "Not Specified",
     *                    "SellerSku": "1051-12883-Blue-Not Specified",
     *                    "price": 0,
     *                    "package_weight": 4,
     *                    "package_length": 160,
     *                    "package_width": 12,
     *                    "package_height": 12,
     *                    "Status": "inactive",
     *                    "quantity": 1111,
     *                    "Images": [
     *                        {
     *                            "Image": "https://my-live-02.slatic.net/p/5554bc476b8167ed8aeeb9f09d4e1993.jpg"
     *                        },
     *                        {
     *                            "Image": "https://my-live-02.slatic.net/p/1172eaa46b28776f9ffe944e3c7d4cd8.jpg"
     *                        },
     *                        {
     *                            "Image": "https://my-live-02.slatic.net/p/73ff045b9c71873fc8078a14a1218e76.jpg"
     *                        }
     *                    ]
     *                }
     *            }
     *        ]
     *    }
     *}
     * @return mixed
     * @throws \Exception
     */
    public function createGlobalProduct(array $productData)
    {
        $productXML = self::generateXMLPayload($productData);
        $this->addApiParam('payload', $productXML);

        return $this->post('/product/global/create');
    }

    /**
     * 使用此API查询指定的全球产品的状态。
     * 在每个站点上创建全局产品需要几分钟。
     *
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=18&path=/product/global/status/get
     *
     * @param array $params {"sellerSku" : "123"} put the "sellerSku" as the key
     *
     * @return mixed
     * @throws \Exception
     */
    public function getGlobalProductStatus(array $params)
    {
        $this->addApiParam('params', $params);

        return $this->get('/product/global/status/get');
    }

    protected function getApiGateWay(): string
    {
        // 指定马来西亚
        return self::API_GATEWAY_URL_MY;
    }
}